<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="Hexo Theme Keep">
    <meta name="description" content="Hexo Theme Keep">
    <meta name="author" content="cm_westwood">
    
    <title>
        
            第6周 |
        
        西木同学的代码训练 2022
    </title>
    
<link rel="stylesheet" href="/code_training_2022/css/style.css">

    <link rel="shortcut icon" href="">
    
<link rel="stylesheet" href="/code_training_2022/css/font-awesome.min.css">

    <script id="hexo-configurations">
    let KEEP = window.KEEP || {};
    KEEP.hexo_config = {"hostname":"cm_westwood.gitee.io","root":"/code_training_2022/","language":"en","path":"search.json"};
    KEEP.theme_config = {"toc":{"enable":true,"number":true,"expand_all":true,"init_open":true},"style":{"primary_color":"#0066CC","avatar":"","favicon":"","article_img_align":"left","left_side_width":"260px","content_max_width":"920px","hover":{"shadow":false,"scale":false},"first_screen":{"enable":true,"background_img":"https://xpoet.cn/images/bg.svg","description":"Keep writing and Keep loving."},"scroll":{"progress_bar":{"enable":true},"percent":{"enable":true}}},"local_search":{"enable":true,"preload":false},"code_copy":{"enable":true,"style":"default"},"pjax":{"enable":false},"lazyload":{"enable":true},"version":"3.4.5"};
    KEEP.language_ago = {"second":"%s seconds ago","minute":"%s minutes ago","hour":"%s hours ago","day":"%s days ago","week":"%s weeks ago","month":"%s months ago","year":"%s years ago"};
  </script>
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
<div class="progress-bar-container">
    
        <span class="scroll-progress-bar"></span>
    

    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                西木同学的代码训练 2022
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/code_training_2022/"
                            >
                                HOME
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/code_training_2022/archives"
                            >
                                ARCHIVES
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/code_training_2022/tags"
                            >
                                TAGS
                            </a>
                        </li>
                    
                    
                        <li class="menu-item search search-popup-trigger">
                            <i class="fas fa-search"></i>
                        </li>
                    
                </ul>
            </div>
            <div class="mobile">
                
                    <div class="icon-item search search-popup-trigger"><i class="fas fa-search"></i></div>
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/code_training_2022/">HOME</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/code_training_2022/archives">ARCHIVES</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/code_training_2022/tags">TAGS</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="article-content-container">

        <div class="article-title">
            <span class="title-hover-animation">第6周</span>
        </div>

        
            <div class="article-header">
                <div class="avatar">
                    <img src="">
                </div>
                <div class="info">
                    <div class="author">
                        <span class="name">cm_westwood</span>
                        
                            <span class="author-label">Lv2</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fas fa-edit"></i>&nbsp;
        <span class="pc">2022-08-20 16:41:25</span>
        <span class="mobile">2022-08-20 16:41</span>
    </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fas fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/code_training_2022/tags/Python/">Python</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/code_training_2022/tags/Jupyter-Notebook/">Jupyter Notebook</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/code_training_2022/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
    
    
</div>

                    </div>
                </div>
            </div>
        

        <div class="article-content markdown-body">
            <p>python 装饰器中的 self；Python 中的强类型检查 - Using Traitlets；数据库可视化工具；python 中的 site-package 和 dist-package；Jupyter Tidbit: IPython’s ! returns an SList</p>
<span id="more"></span>

<p><a href="/code_training_2022/第6周/配套代码.html" style="text-align: center; display: block;">第6周的配套代码</a></p>
<h1 id="python-装饰器中的-self"><a href="#python-装饰器中的-self" class="headerlink" title="python 装饰器中的 self"></a>python 装饰器中的 self</h1><p>self 其实就是实例化类之后的一个 kwargs，所以写类的装饰器的时候只需要从 **kwargs 中拆一个 self 形参出来就能拿到实例化类的自身了。可借助 <code>pip install decorator</code> 包快速构建类方法装饰器</p>
<blockquote>
<p><a class="link"   target="_blank" rel="noopener" href="https://pypi.org/project/decorator/" >https://pypi.org/project/decorator/<i class="fas fa-external-link-alt"></i></a></p>
<p><a class="link"   target="_blank" rel="noopener" href="https://stackoverflow.com/questions/8375862/self-in-python-decorators" >https://stackoverflow.com/questions/8375862/self-in-python-decorators<i class="fas fa-external-link-alt"></i></a></p>
<p><a class="link"   target="_blank" rel="noopener" href="https://wiki.python.org/moin/PythonDecoratorLibrary#Function_Timeout" >PythonDecoratorLibrary - Python Wiki<i class="fas fa-external-link-alt"></i></a></p>
</blockquote>
<h1 id="Python-中的强类型检查-Using-Traitlets"><a href="#Python-中的强类型检查-Using-Traitlets" class="headerlink" title="Python 中的强类型检查 - Using Traitlets"></a>Python 中的强类型检查 - Using Traitlets</h1><p>有一道很经典的面试题，python 有没有重载模式，答案是没有，因为 python 根本不需要重载形参，形参的类型检查（import typing）仅仅只是编写代码的时候做个提示，运行时并不会发生任何报错异常，一切类型的对象都可以赋值给这个形参，所以根本用不到重载的概念。</p>
<p>但是实践过程中，遇到了需要严格检查数据类型的数据结构，所以在想 python 有没有强类型检查的方法。</p>
<p>我试过去傻傻的百度搜索，bing 搜索，谷歌搜索过这个问题，最后发现一篇可能是最合理的解决方法可能是这两个：</p>
<ul>
<li><a class="link"   target="_blank" rel="noopener" href="https://blog.csdn.net/HayPinF/article/details/107423526" >利用python装饰器实现函数的“类型检查“_HayPinF的博客-CSDN博客<i class="fas fa-external-link-alt"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="http://www.zzvips.com/article/86188.html" >在Python 3中实现类型检查器的简单方法_Python_脚本之家<i class="fas fa-external-link-alt"></i></a></li>
</ul>
<p>现在看来这种方法太傻了啊，最后我是在精读这个人的代码 <a class="link"   target="_blank" rel="noopener" href="https://github.com/oschuett/appmode/blob/master/appmode/server_extension.py" >https://github.com/oschuett/appmode/blob/master/appmode/server_extension.py<i class="fas fa-external-link-alt"></i></a> 的时候发现了这么一个最对我胃口的库 <a class="link"   target="_blank" rel="noopener" href="https://traitlets.readthedocs.io/en/stable/using_traitlets.html#default-values-and-checking-type-and-value" >https://traitlets.readthedocs.io/en/stable/using_traitlets.html#default-values-and-checking-type-and-value<i class="fas fa-external-link-alt"></i></a></p>
<h1 id="数据库可视化工具"><a href="#数据库可视化工具" class="headerlink" title="数据库可视化工具"></a>数据库可视化工具</h1><p>Apache Superset is a modern data exploration and visualization platform <a class="link"   target="_blank" rel="noopener" href="https://superset.apache.org/" >https://superset.apache.org<i class="fas fa-external-link-alt"></i></a></p>
<h1 id="python-中的-site-package-和-dist-package"><a href="#python-中的-site-package-和-dist-package" class="headerlink" title="python 中的 site-package 和 dist-package"></a>python 中的 site-package 和 dist-package</h1><p>当使用 import 导入一个包或模块时，Python 会去一些目录下查找，而这些目录是有优先级顺序的，可以使用 sys.path 查看，或者使用<code>python -m site</code>查看。可以发现，python 中含有 <strong>site-package</strong> 和 <strong>dist-package</strong> 两个包空间目录，有些包是安装在 <strong>site-packages</strong> 下，而有些包安装在 <strong>dist-packages</strong> 下。一般情况下，用户安装包会在 <strong>site-package</strong> 目录下。而 <strong>dist-packages</strong> 其实是 debian 系的 Linux 系统（如 Ubuntu）才特有的目录，当使用 apt 去安装的 Python 包会使用 dist-packages，而使用 pip 或者 easy_install 安装的包还是照常安装在 site-packages 下。所以可以直接将代码包拷贝到 site-packages 下就可以全局使用了。</p>
<blockquote>
<p><a class="link"   target="_blank" rel="noopener" href="https://stackoverflow.com/questions/9387928/whats-the-difference-between-dist-packages-and-site-packages" >python - dist-packages 和 site-packages 有什么区别？ - 堆栈溢出<i class="fas fa-external-link-alt"></i></a></p>
</blockquote>
<h1 id="Jupyter-Tidbit-IPython’s-returns-an-SList"><a href="#Jupyter-Tidbit-IPython’s-returns-an-SList" class="headerlink" title="Jupyter Tidbit: IPython’s ! returns an SList"></a>Jupyter Tidbit: IPython’s ! returns an SList</h1><p>我现在才知道，原来 IPython 中的可以这样<code>ls = !ls</code>获取命令行语句的返回结果</p>
<blockquote>
<p><a class="link"   target="_blank" rel="noopener" href="https://mindtrove.info/jupyter-tidbit-ipython-slists/" >Jupyter Tidbit: IPython’s ! returns an SList - Parente’s Mindtrove<i class="fas fa-external-link-alt"></i></a></p>
</blockquote>
<p>类似黑科技还有：</p>
<blockquote>
<p><a class="link"   target="_blank" rel="noopener" href="https://mindtrove.info/jupyter-tidbit-config-paths" >Jupyter Tidbit: Config, data, and runtime paths<i class="fas fa-external-link-alt"></i></a></p>
<p><a class="link"   target="_blank" rel="noopener" href="https://mindtrove.info/jupyter-tidbit-display-handles" >Jupyter Tidbit: Display handles<i class="fas fa-external-link-alt"></i></a></p>
<p><a class="link"   target="_blank" rel="noopener" href="https://mindtrove.info/jupyter-tidbit-run-and-say-done" >Jupyter Tidbit: Run and say “done!”<i class="fas fa-external-link-alt"></i></a></p>
</blockquote>

        </div>

        

        
            <ul class="post-tags-box">
                
                    <li class="tag-item">
                        <a href="/code_training_2022/tags/Python/">#Python</a>&nbsp;
                    </li>
                
                    <li class="tag-item">
                        <a href="/code_training_2022/tags/Jupyter-Notebook/">#Jupyter Notebook</a>&nbsp;
                    </li>
                
                    <li class="tag-item">
                        <a href="/code_training_2022/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/">#数据库</a>&nbsp;
                    </li>
                
            </ul>
        

        
            <div class="article-nav">
                
                    <div class="article-prev">
                        <a class="prev"
                           rel="prev"
                           href="/code_training_2022/2022/11/25/%E7%AC%AC7%E5%91%A8/"
                        >
                            <span class="left arrow-icon flex-center">
                              <i class="fas fa-chevron-left"></i>
                            </span>
                            <span class="title flex-center">
                                <span class="post-nav-title-item">第7周</span>
                                <span class="post-nav-item">Prev posts</span>
                            </span>
                        </a>
                    </div>
                
                
                    <div class="article-next">
                        <a class="next"
                           rel="next"
                           href="/code_training_2022/2022/07/23/%E7%AC%AC5%E5%91%A8/"
                        >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">第5周</span>
                                <span class="post-nav-item">Next posts</span>
                            </span>
                            <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        

        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
              <span>2022</span>
              -
            
            2023&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;<a href="/">cm_westwood</a>
        </div>
        
        <div class="theme-info info-item">
            Powered by <a target="_blank" href="https://hexo.io">Hexo</a>&nbsp;|&nbsp;Theme&nbsp;<a class="theme-version" target="_blank" href="https://github.com/XPoet/hexo-theme-keep">Keep v3.4.5</a>
        </div>
        
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        
            <li class="tools-item page-aside-toggle">
                <i class="fas fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-expand-width flex-center">
            <i class="fas fa-arrows-alt-h"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="arrow-up fas fa-arrow-up"></i>
                <span class="percent"></span>
            </li>
        
    </ul>
</div>

    </div>

    
        <aside class="page-aside">
            <div class="post-toc-wrap">
    <div class="post-toc">
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#python-%E8%A3%85%E9%A5%B0%E5%99%A8%E4%B8%AD%E7%9A%84-self"><span class="nav-number">1.</span> <span class="nav-text">python 装饰器中的 self</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Python-%E4%B8%AD%E7%9A%84%E5%BC%BA%E7%B1%BB%E5%9E%8B%E6%A3%80%E6%9F%A5-Using-Traitlets"><span class="nav-number">2.</span> <span class="nav-text">Python 中的强类型检查 - Using Traitlets</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B7%A5%E5%85%B7"><span class="nav-number">3.</span> <span class="nav-text">数据库可视化工具</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#python-%E4%B8%AD%E7%9A%84-site-package-%E5%92%8C-dist-package"><span class="nav-number">4.</span> <span class="nav-text">python 中的 site-package 和 dist-package</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Jupyter-Tidbit-IPython%E2%80%99s-returns-an-SList"><span class="nav-number">5.</span> <span class="nav-text">Jupyter Tidbit: IPython’s ! returns an SList</span></a></li></ol>
    </div>
</div>
        </aside>
    

    <div class="image-viewer-container">
    <img src="">
</div>


    
        <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
          <span class="search-input-field-pre">
            <i class="fas fa-keyboard"></i>
          </span>
            <div class="search-input-container">
                <input autocomplete="off"
                       autocorrect="off"
                       autocapitalize="off"
                       placeholder="Search..."
                       spellcheck="false"
                       type="search"
                       class="search-input"
                >
            </div>
            <span class="popup-btn-close">
                <i class="fas fa-times"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fas fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>

    

</main>




<script src="/code_training_2022/js/utils.js"></script>

<script src="/code_training_2022/js/main.js"></script>

<script src="/code_training_2022/js/header-shrink.js"></script>

<script src="/code_training_2022/js/back2top.js"></script>

<script src="/code_training_2022/js/dark-light-toggle.js"></script>



    
<script src="/code_training_2022/js/local-search.js"></script>




    
<script src="/code_training_2022/js/code-copy.js"></script>




    
<script src="/code_training_2022/js/lazyload.js"></script>



<div class="post-scripts">
    
        
<script src="/code_training_2022/js/left-side-toggle.js"></script>

<script src="/code_training_2022/js/libs/anime.min.js"></script>

<script src="/code_training_2022/js/toc.js"></script>

    
</div>



</body>
</html>
